//
//  ViewController.m
//  录音
//
//  Created by 周成龙 on 17/3/12.
//  Copyright © 2017年 ZCL. All rights reserved.
//

#import "ViewController.h"

@import AVFoundation;

@interface ViewController () {
    AVAudioRecorder *_recoder;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)start:(id)sender {
    
    if (!_recoder) {
        
        NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        
        NSString *filePath = [path stringByAppendingPathComponent:@"123.wav"];
        NSURL *url = [NSURL fileURLWithPath:filePath];
        
        NSDictionary *settingDic =@{
                                    // 音质
                                    AVEncoderAudioQualityKey : @(AVAudioQualityLow),
                                    // 比特率
                                    AVEncoderBitRateKey      : @(16),
                                    // 采样率
                                    AVSampleRateKey          : @(8000),
                                    // 声道
                                    AVNumberOfChannelsKey    : @(2),
                                    };
        NSError *error;
        _recoder = [[AVAudioRecorder alloc] initWithURL:url settings:settingDic error:&error];
        if (error) {
            NSLog(@"----%@", error.description);
        }else {
            [_recoder record];
        }
    }
    
}

- (IBAction)stop:(id)sender {
    [_recoder stop];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
